/*
 * TetrisPanel.java
 *
 * Created on 2008. március 23., 22:16
 */

package sztetris.ui;

import java.awt.Graphics;
import java.awt.*;
 
/**
 *
 * @author  szityu
 */
public class TetrisPanel extends javax.swing.JPanel {
    
    /** Creates new form TetrisPanel */
    public TetrisPanel() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 396, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 296, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

     public final static int TILE_SIZE = 15;
     public tetrisengine.TetrisGame game;
     
     public void setGame(tetrisengine.TetrisGame game)
     {
        this.game = game;
     } 
     
     @Override protected void paintComponent(Graphics g)
     {
        
        if ((game != null) && (game.state.board.length != 0))
        {
            int i, j;
            Color c;
            for (i=0; i<game.width+2; i++)
            {
                for (j=0; j<game.height+1; j++)
                {
                    c = tetrisengine.TetrisGame.tilecolor[game.state.board[i + tetrisengine.TetrisGame.PADDING-1][j  + tetrisengine.TetrisGame.PADDING]];
                    g.setColor(c);
                    g.fillRect(i*TILE_SIZE, j*TILE_SIZE, TILE_SIZE-1, TILE_SIZE-1);
                }
            }
        }
        else
        {
            g.setColor(Color.RED);
            g.fillRect(10, 10, 40, 40);
        }
    }
   
     
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
}
